var app = getApp()
var baseUrl = app.globalData.baseUrl
Page({

  data: {
    myRecord: null
  },

  async onLoad(){
    wx.showLoading({
      title: '加载中',
    })
    let userInfo = wx.getStorageSync('userInfo')
    //获取用户个人的竞拍记录
    wx.request({
      url: baseUrl+'goodsAuctionRecord/getUserRecord/'+userInfo._openid,
      method: 'GET',
      success: res =>{
        let allRecord = res.data
    //为每一个竞拍记录添加所属的商品信息
    var t = 0
    for(let i = 0;i< allRecord.length;i++){
      let goodsId = allRecord[i].goodsId
      wx.request({
        url: baseUrl+'goods/getGood/'+goodsId,
        method: 'POST',
        success: res => {
          allRecord[i].goodsInfo= res.data
          t++
          if(t>=allRecord.length){
            this.setData({
              myRecord: allRecord
            })
            wx.hideLoading({
              success: (res) => {},
            })
          }
        }
      })
    }
      }
    })

  },
  toGoods(e) {
    let goodsid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goods/goods?goodsid=' + goodsid,
    })
  }
})